using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using BE;

namespace DA
{
    public class CommonDA
    {
        #region Metodos Publicos
        public static Boolean ValidarNombre(long uidId, Int32 intUsuarioId, String strNombre, String strTipo)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("ValidarNombre");
            sqlClient.AddInParameter(dbCmd, "@Id", DbType.Int64, uidId);
            sqlClient.AddInParameter(dbCmd, "@IdUsuario", DbType.Int32, intUsuarioId);
            sqlClient.AddInParameter(dbCmd, "@Nombre", DbType.String, strNombre);
            sqlClient.AddInParameter(dbCmd, "@Tipo", DbType.String, strTipo);
            sqlClient.AddOutParameter(dbCmd, "@IsValid", DbType.Boolean, 1);
            sqlClient.ExecuteNonQuery(dbCmd);

            return Convert.ToBoolean(sqlClient.GetParameterValue(dbCmd, "@IsValid"));
        }
        public static DataTable ObtenerDepartamentos()
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("ObtenerDepartamentos");
            return sqlClient.ExecuteDataSet(dbCmd).Tables[0];
        }

        //
        public static DataTable ObtenerTodosTipoCambios(String strCriterio)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("sp_ObtenerTodosTipoCambios");
            sqlClient.AddInParameter(dbCmd, "@criterio", DbType.String, strCriterio);
            return sqlClient.ExecuteDataSet(dbCmd).Tables[0];
        }
        public static DataTable ObtenerProvincias(Guid uidDepartamentoId)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("ObtenerProvincias");
            sqlClient.AddInParameter(dbCmd, "@DepartamentoId", DbType.Guid, uidDepartamentoId);
            return sqlClient.ExecuteDataSet(dbCmd).Tables[0];
        }
        public static DataTable ObtenerDistritos(Guid uidProvinciaId)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("ObtenerDistritos");
            sqlClient.AddInParameter(dbCmd, "@ProvinciaId", DbType.Guid, uidProvinciaId);
            return sqlClient.ExecuteDataSet(dbCmd).Tables[0];
        }
        #endregion
    }
}
